package com.luzhikun.HVJdemol.servlet;

import com.luzhikun.HVJdemol.db.JDBCUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;

@WebServlet(name = "TestServlet", value = "/testServlet")
public class TestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/html;charset=UTF-8");
        JDBCUtil jdbcUtil=new JDBCUtil();
        Connection connection=null;
        try {
            connection = jdbcUtil.getConnection();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            try {
                jdbcUtil.closeAll(connection,null,null);
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        PrintWriter writer = response.getWriter();
        writer.println(connection);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
